<template>
	<view class="entrepreneurship-page page">
		<image class="top-bg" :src="cloudStorage+'index/top-bg.png'"></image>
		<CustomNav :isBack="true" :color="titleColor" :topBgColor="topBgColor" title="创业“蓝海”"></CustomNav>
		<view @click="navigate('/page_pack/entrepreneurship/release?type=add')" class="release-btn">
			<view class="title-block">
				<image :src="cloudStorage+'index/release.png'" class="release-icon"></image>
				<view class="title FZHZGBJ">我要发布</view>
			</view>
			<view class="sub-title">可发布厂房租房、门店转让、房屋出售等信息</view>
		</view>
		<view class="content-block">
			<view class="search-block">
				<image :src="cloudStorage+'index/search.png'" class="search-icon"></image>
				<input class="form-ctrl" v-model="conf.keyword" placeholder-class="input-placeholder"
					placeholder="请输入搜索关键词" maxlength="20" @confirm="handleRefresh" />
			</view>
			<view class="select-block">
				选择乡镇：
				<NormalPicker v-if="township.length>0" style="display: block;" fs="28" :range="township"
					v-model="conf.township" name="townshipName" class="form-ctrl"></NormalPicker>
				<view class="iconfont icon-xiajiantou"></view>
			</view>
			<view class="list-block">
				<template v-if="list.length>0">
					<EntrepreneurshipItem :info="item" v-for="item in list" :key="item.id"></EntrepreneurshipItem>
				</template>
				<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
				<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util'
	import {
		entrepreneurshipList
	} from '@/api/entrepreneurship'
	import EntrepreneurshipItem from '@/page_pack/components/ListItem/EntrepreneurshipItem'
	import {
		townshipList
	} from '@/api/index'
	import NormalPicker from '@/page_pack/components/Picker/NormalPicker'
	export default {
		components: {
			EntrepreneurshipItem,
			NormalPicker
		},
		data() {
			return {
				conf: {
					page: 1,
					limit: 20,
					keyword: '',
					township: 0
				},
				more: true,
				titleColor: '#000',
				topBgColor: 'rgba(0,0,0,0)',
				list: [

				],
				township: []
			}
		},
		watch: {
			"conf.township": {
				handler() {
					this.handleRefresh();
				}
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				this.getList('refresh');
			},
			getList(type = '') {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				entrepreneurshipList(this.conf).then(res => {
					this.list = type == 'refresh' ? res.list : [...this.list, ...res.list];
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
			getConf() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				townshipList().then(res => {
					this.township = [{
						id: 0,
						townshipName: '全部'
					}, ...res];
					this.getList('refresh');
				})
			}
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad() {
			this.getConf();
		}
	}
</script>

<style lang="scss" scoped>
	.entrepreneurship-page {
		width: 100%;
		position: relative;

		.top-bg {
			width: 100%;
			height: 480rpx;
		}

		.release-btn {
			position: absolute;
			width: calc(100% - 60rpx);
			transform: translate(-50%, -50%);
			left: 50%;
			top: 430rpx;
			height: 220rpx;
			background: linear-gradient(to right, #1F946A, #CFCF32);
			border-radius: 8px;
			z-index: 2;
			display: flex;
			flex-direction: column;
			justify-content: center;
			padding-left: 60rpx;
			box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.5);

			.title-block {
				display: flex;
				align-items: center;
				margin-bottom: 30rpx;

				.release-icon {
					width: 60rpx;
					height: 60rpx;
					margin-right: 20rpx;
				}

				.title {
					color: #fff;
					font-size: 40rpx;
				}
			}

			.sub-title {
				color: #fff;
				font-size: 28rpx;
			}
		}

		.content-block {
			position: relative;
			margin-top: -50rpx;
			width: 100%;
			border-radius: 20px 20px 0 0;
			background: #F7F6F9;
			padding: 30rpx;
			padding-top: 150rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;

			.search-block {
				width: 100%;
				display: flex;
				align-items: center;
				height: 80rpx;
				border-radius: 20px;
				background: #E7E6E9;
				padding-left: 40rpx;

				.search-icon {
					height: 50rpx;
					width: 50rpx;
					margin-right: 20rpx;
				}

				.form-ctrl {
					width: calc(100% - 110rpx);
					height: 100%;
					font-size: 28rpx;
				}
			}

			.select-block {
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				font-size: 28rpx;

				.iconfont {
					margin-left: 10rpx;
				}
			}

			.list-block {
				width: 100%;
				padding-top: 30rpx;
			}
		}
	}
</style>